package com.xyht.sca_s.student_manage_system.modules.student_subsidies.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.student_subsidies.entity.req.SmsStudentSubsidiesApplyReq;
import com.xyht.sca_s.student_manage_system.modules.student_subsidies.service.SmsStudentSubsidiesApplyService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * 国家助学金申请 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-02-26
 */
@RestController
@RequestMapping("/subsidies/apply")
@SecretBody
public class SmsStudentSubsidiesApplyController {
    @Autowired
    private SmsStudentSubsidiesApplyService smsStudentSubsidiesApplyService;
    @Autowired
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty(value = "助学金申请提交")
    @PostMapping("/submit")
    public ResponseResult submitSubsidiesApply(@RequestBody SmsStudentSubsidiesApplyReq smsStudentSubsidiesTaskReq,
                                               HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsStudentSubsidiesApplyService.submitSubsidiesApply(smsStudentSubsidiesTaskReq, user_id);
    }

    @ApiModelProperty(value = "助学金申请驳回提交")
    @PostMapping("/rejectSubmit")
    public ResponseResult submitSubsidiesRejectApply(@RequestBody SmsStudentSubsidiesApplyReq smsStudentSubsidiesTaskReq,
                                                     HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsStudentSubsidiesApplyService.submitSubsidiesRejectApply(smsStudentSubsidiesTaskReq, user_id);
    }

    @ApiModelProperty(value = "助学金申请驳回")
    @PostMapping("/reject")
    public ResponseResult rejectSubsidiesApply(@RequestBody SmsStudentSubsidiesApplyReq smsStudentSubsidiesTaskReq) {
        return smsStudentSubsidiesApplyService.rejectSubsidiesApply(smsStudentSubsidiesTaskReq);
    }

    @ApiModelProperty(value = "获取本人助学金可申请列表")
    @GetMapping("/ownTaskList")
    public ResponseResult getOwnSubsidiesTaskList(HttpServletRequest request,
                                                  @RequestParam(value = "search_str", required = false) String search_str,
                                                  @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                  @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsStudentSubsidiesApplyService.getOwnSubsidiesTaskList(pageNum, pageSize, user_id,search_str);
    }

    @ApiModelProperty(value = "获取本人助学金申请历史")
    @GetMapping("/history")
    public ResponseResult getSubsidiesApplyHistory(HttpServletRequest request,
                                                   @RequestParam(value = "search_str", required = false) String search_str,
                                                   @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                   @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsStudentSubsidiesApplyService.getSubsidiesApplyHistory(pageNum, pageSize, user_id,search_str);
    }

    @ApiModelProperty(value = "助学金填写获取")
    @GetMapping("/fill")
    public ResponseResult getSubmitSubsidiesApply(HttpServletRequest request,
                                                  @RequestParam(value = "task_id") String task_id) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsStudentSubsidiesApplyService.getSubmitSubsidiesApply(task_id, user_id);
    }

    @ApiModelProperty(value = "助学金申请表详情")
    @GetMapping("/detail")
    public ResponseResult getSubsidiesApplyDetail( @RequestParam(value = "apply_id") String apply_id) {
        return smsStudentSubsidiesApplyService.getSubsidiesApplyDetail(apply_id);
    }

    @ApiModelProperty(value = "助学金申请表下载")
    @GetMapping("/download")
    public ResponseResult exportSubsidiesApply(@RequestParam(value = "apply_id") String apply_id, HttpServletResponse response) {
        return smsStudentSubsidiesApplyService.exportSubsidiesApply(apply_id,response);
    }

}

